package com.ruoyi.user.service.impl;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.ruoyi.user.Utils.AliyunOssUtil;
import com.ruoyi.user.Utils.BlankCardUtils;
import com.ruoyi.user.Utils.IdCardUtils;
import com.ruoyi.user.common.ResultInfo;
import com.ruoyi.user.mapper.UserRegistMapper;
import com.ruoyi.user.pojo.Detall;
import com.ruoyi.user.pojo.User;
import com.ruoyi.user.service.UserRegistService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Random;

@Service
public class UserRegistServiceImpl implements UserRegistService {

    @Autowired
    UserRegistMapper userRegistMapper;



    @Override
    public ResultInfo insert(User user) {
        //先查询用户是否存在，存在的话就给出错误提示
//        User user1 = userRegistMapper.registInsert(user);
//        if(user1 != null){
//            return new ResultInfo(false,5000,"用户名已存在，不能注册",null);
//        }
        //身份证认证
        if(user.getIdcard().length()>0){
            boolean booleans = IdCardUtils.sendIdCard(user.getUser_name(), user.getIdcard());
            if(booleans =false){
                return new ResultInfo(200,"身份证信息和名字不匹配",null);
            }
        }
        if(user.getBankcard().length()>0){
            boolean booleans = BlankCardUtils.sendBlankCard(user.getUser_name(), user.getIdcard(),user.getBankcard());
            if(booleans =false){
                return new ResultInfo(200,"银行卡和名字不匹配",null);
            }
        }

        //用户不存在的话就可以添加
        //使用bcrypt给密码加密
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String encode = encoder.encode(user.getUser_pwd());
        //加密成功后放回到pwd中进行添加
        user.setUser_pwd(encode);
        userRegistMapper.insert(user);
        return new ResultInfo(2000,"用户注册成功",null);

    }



}
